package com.gqb.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport{
	protected void write(Map<String, Object> map){
		HttpServletResponse response=ServletActionContext.getResponse();
		response.setContentType("text/html");
		//String mapJsonString=JSON.toJSONString(map, true);
		String jsonString=new Gson().toJson(map);
		try {
			PrintWriter out=response.getWriter();
			out.write(jsonString);
            out.flush();
            out.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	protected void write(String map){
		HttpServletResponse response=ServletActionContext.getResponse();
		response.setContentType("text/html");
		//String mapJsonString=JSON.toJSONString(map, true);
		try {
			PrintWriter out=response.getWriter();
			out.write(map);
            out.flush();
            out.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
